import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';

import format from '@dfeidao/atom-web/dt/format';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

import set from '@dfeidao/atom-web/local/set';

export default async function a001(fd: IFeidaoAiBrowserComponent, dtno: string) {
	// todo
	// 显示  获值
	const word_dtl = fd.data.node.querySelector<HTMLDivElement>('[data-id="word_detail"]');
	set_node_cls(word_dtl, 'display-n', false);
	const res = await nodejs<{
		res: Array<{
			create_time: number,
			start_time: number,
			finish_time: number,
			completion_time: number,
			source_type: string,
			work_order_status: string
		}>
	}>('knowledge-base/zj-000002/s001', {
		filter: {
			work_bill_no: dtno
		}
	});
	const ral = res.res.map((n) => {
		return {
			...n, create_time: format(n.create_time, 2), start_time: format(n.start_time, 2),
			finish_time: format(n.finish_time, 2), completion_time: format(n.completion_time, 2)
		};
	});
	const res2 = await nodejs<{ res2: Array<{ record_no: string }> }>('knowledge-base/zj-000002/s003', {
		filter: {
			work_bill_no: dtno
		}
	});

	// const res1 = await nodejs<{ res2: Array<{}> }>('knowledge-base/zj-000002/s002', {
	// 	filter: {
	// 		work_bill_no: dtno
	// 	}
	// });


	// 处理数据

	const record_no = res2.res2[0].record_no;

	set(fd, 'record_no', record_no);




	if (res.res.length > 0) {
		render(fd, ral, p001, 'p001', "inner");
		render(fd, ral, p002, 'p002', "inner");
	}

	if (res2.res2.length > 0) {
		render(fd, res2.res2, p003, 'p003', 'inner');
	}










}
